package com.haixiaoke.saas.enterprise.tenant.controller;

import com.haixiaoke.saas.common.annotation.RepeatSubmit;
import com.haixiaoke.saas.common.annotation.TenantScope;
import com.haixiaoke.saas.common.core.domain.AjaxResult;
import com.haixiaoke.saas.common.core.page.TableDataInfo;
import com.haixiaoke.saas.system.framework.security.util.SecurityUtils;
import com.haixiaoke.saas.tenant.domain.WechatAccount;
import com.haixiaoke.saas.tenant.service.IWechatAccountService;
import com.haixiaoke.saas.system.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 微信商户号信息Controller
 *
 * @author xiaolong
 * @date 2023-12-26
 */
@RestController
@RequestMapping("/enterprise/tenant/wechatAccount")
public class EnterpriseWechatAccountController extends BaseController {
    @Autowired
    private IWechatAccountService wechatAccountService;

    /**
     * 查询微信商户号信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(WechatAccount wechatAccount) {
        startPage();
        List<WechatAccount> list = wechatAccountService.selectWechatAccountList(wechatAccount);
        return getDataTable(list);
    }

    /**
     * 获取微信商户号信息详细信息
     */
    @GetMapping
    public AjaxResult getInfo() {
        return success(wechatAccountService.selectWechatAccountByWechatAccountId(SecurityUtils.getLoginUser().getTenantId()));
    }

    /**
     * 修改微信商户号信息
     */
    @PutMapping
    @RepeatSubmit
    public AjaxResult edit(WechatAccount wechatAccount, @RequestParam(required = false) MultipartFile file) {
        wechatAccount.setTenantId(SecurityUtils.getLoginUser().getTenantId());
        return toAjax(wechatAccountService.updateWechatAccount(wechatAccount, file));
    }

    /**
     * 删除微信商户号信息
     */
    @DeleteMapping("/{wechatAccountIds}")
    @RepeatSubmit
    public AjaxResult remove(@PathVariable Long[] wechatAccountIds) {
        return toAjax(wechatAccountService.deleteWechatAccountByWechatAccountIds(wechatAccountIds));
    }
}
